package com.qk.management.handler;

import com.qk.common.Result;
import com.qk.common.exception.CommonException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    
    //处理异常
    @ExceptionHandler(value = Exception.class)
    public Result handleException(Exception e){//方法形参中指定能够处理的异常类型
        log.error("服务器异常:{}", e.getMessage());
        //捕获到异常之后，响应一个标准的Result
        return Result.error("您的网络有问题，请稍后重试");
    }
    @ExceptionHandler(value = CommonException.class)
    public Result handleCommonException(CommonException e){

        return Result.error(e.getMessage());
    }
    
}